//
//  TeacherAskController.swift
//  BodyBuilding
//
//  Created by franze on 2017/10/20.
//  Copyright © 2017年 franze. All rights reserved.
//

import UIKit

class TeacherAskController: UIViewController {
    var txtView:CustomTextView!
    var masterID:String!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        viewConfig()
    }
    
    func viewConfig(){
        view.backgroundColor = UIColor.white
        
        let navBar = CustomNavBar(frame: CGRect(origin: .zero, size: CGSize(width: WIDTH, height: 64)))
        navBar.initialize(text: "提问")
        view.addSubview(navBar)
        
        txtView = CustomTextView(frame: CGRect(x: 15, y: 64, width: WIDTH-30, height: 250))
        txtView.placeholder = "不超过140个字"
        view.addSubview(txtView)
        
        let submitBtn = UIButton(frame: CGRect(x: 0, y: 354, width: 100, height: 44))
        submitBtn.backgroundColor = UIColor.white
        submitBtn.center.x = WIDTH/2-100
        submitBtn.setTitle("提交", for: .normal)
        submitBtn.setTitleColor(.black, for: .normal)
        submitBtn.layer.borderColor = UIColor.lightGray.cgColor
        submitBtn.layer.borderWidth = 1
        submitBtn.layer.cornerRadius = 8
        view.addSubview(submitBtn)
        
        let cancelBtn = UIButton(frame: CGRect(x: 0, y: 354, width: 100, height: 44))
        cancelBtn.backgroundColor = UIColor.white
        cancelBtn.center.x = WIDTH/2+100
        cancelBtn.setTitle("取消", for: .normal)
        cancelBtn.setTitleColor(.black, for: .normal)
        cancelBtn.layer.borderColor = UIColor.lightGray.cgColor
        cancelBtn.layer.borderWidth = 1
        cancelBtn.layer.cornerRadius = 8
        view.addSubview(cancelBtn)
        
        submitBtn.addTarget(self, action: #selector(submit), for: .touchUpInside)
        navBar.backBtn.addTarget(self, action: #selector(back), for: .touchUpInside)
    }
    
    @objc func submit(){
        let parameter:NSDictionary = [
            "SessionID" :   LoginModel.sessionID,
            "mod"       :   "masterfaq",
            "master_id" :   masterID,
            "question"  :   txtView.text,
            "user_id"   :   LoginModel.userID
        ]
        Networking.shared.creat(parameter: parameter) {
            let popup = Popup()
            popup.appear(title: "提交成功", action: {
                _ = self.navigationController?.popViewController(animated: true)
            })
        }
    }
    
    @objc func back(){
        _ = navigationController?.popViewController(animated: true)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}
